# Resource-centric layout. This separates resources into separate named
# graphs and follows the graph-per-resource pattern
# (http://patterns.dataincubator.org/book/graph-per-resource.html). This aligns
# quite well with the resource-centrism of LDP and of the SPARQL Graph Store
# Protocol (https://www.w3.org/TR/sparql11-http-rdf-update/) which should be
# used by the software implementation to minimize data structure translation.
#
# A graph identified by the resource UID is the current state of that resource.
# Other resources (graphs) can be present representing various previous states
# of the resource and are identified by the resource UUID with a `:` (colon)
# and the version UID appended.
# E.g. a resource with a UID of `a/b/c` will be internally stored within a
# named graph `info:fcstate/a/b/c`; the subject will be `info:fcres/a/b/c`;
# a previous version could be `info:fcstate/a/b/c:version1` and the publicly
# exposed URL could be http://webroot.org/ldp/a/b/c`.
#
# The relationships between resources and thir versions and other metadata not
# meant to be directly exposed by the LDP API are in one "metadata" graph.

PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX fcrepo: <http://fedora.info/definitions/v4/repository#>
PREFIX fcsystem: <info:fcsystem/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
PREFIX ns: <http://example.edu/lakesuperior/ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

# System root. It cannot be deleted.
fcsystem:__root__ {
    <info:fcres/> a
        fcrepo:RepositoryRoot , fcrepo:Resource , fcrepo:Container ,
        ldp:Container , ldp:BasicContainer , ldp:RDFSource ;
    .
}

# Metadata graphs. Each of these is a "companion" of the content graph.
# All triples that describe the stored resource state go here. Also triples
# used by the application business logic are stored here.
# These are a convenient way to get resource metadata (e.g. with a HEAD
# request) without loading large graphs, e.g. ones with many children
# or many user-provided properties.
<info:fcmeta/a/b/c> {
  <info:fcstate/a/b/c> a fcsystem:CurrentState ;
    # This may be redundant if we use naming conventions, but still good LD practice.
    fcsystem:stateOf <info:fcres/a/b/c> ;
    fcsystem:hasVersion
      <info:fcstate/a/b/c:v1> , <info:fcstate/a/b/c:v2> , <info:fcstate/a/b/c:v3> ;
  .
  <info:fcres/a/b/c> a fcrepo:Resource ;
    # Timestamps are simplified for readability.
    fcrepo:created "2017-11-23"^^xsd:date ;
    fcrepo:lastModified "2017-11-27"^^xsd:date ;
}

<info:fcmeta/a/b/c:v1> {
  <info:fcstate/a/b/c:v1>
    fcsystem:stateOf <info:fcres/a/b/c:v1> ;
    fcrepo:created "2017-11-24"^^xsd:date ;
  .
  <info:fcres/a/b/c:v1> a fcrepo:Version ;
    fcrepo:created "2017-11-23"^^xsd:date ;
    fcrepo:lastModified "2017-11-23"^^xsd:date ;
  .
}

<info:fcmeta/a/b/c:v2> {
  <info:fcstate/a/b/c:v2>
    fcsystem:stateOf <info:fcres/a/b/c:v2> ;
    a fcrepo:Version ;
    fcrepo:created "2017-11-25"^^xsd:date ;
  .
  <info:fcres/a/b/c:v2> a fcrepo:Version ;
    fcrepo:created "2017-11-23"^^xsd:date ;
    fcrepo:lastModified "2017-11-24"^^xsd:date ;
  .
}

<info:fcmeta/a/b/c:v3> {
  <info:fcstate/a/b/c:v3>
    fcsystem:stateOf <info:fcres/a/b/c:v3> ;
    a fcrepo:Version ;
    fcrepo:created "2017-11-26"^^xsd:date ;
  .
  <info:fcres/a/b/c:v3> a fcrepo:Version ;
    fcrepo:created "2017-11-23"^^xsd:date ;
    fcrepo:lastModified "2017-11-25"^^xsd:date ;
  .
}

# Pairtree information not passed to the client but used to mimic
# hierarchical structures.
<info:fcmeta/a> {
  <info:fcstate/a>
    fcsystem:stateOf <info:fcres/a> ;
  .
  <info:fcres/a>
    a ldp:Container , ldp:BasicContainer , ldp:Resource , ldp:RDFSSource ;
    a fcrepo:Pairtree ;
    # fcsystem:contains only applies to Pairtrees and is used to mimic path
    # hierarchies.
    fcsystem:contains <info:fcres/a/b> ;
    ldp:contains <info:fcres/a/b/c> ;
  .
}

<info:fcmeta/a/b> {
  <info:fcstate/a/b>
    fcsystem:currentStateOf <info:fcres/a/b> ;
  .
  <info:fcres/a/b>
    a fcrepo:Pairtree ;
    fcsystem:contains <info:fcres/a/b/c> ;
  .

}

# Resource graph. These statements are user-provided and not used for any
# application business logic.
# Note that "fragments", i.e. hash URIs, are stored within the same graph.
<info:fcstate/a/b/c> {
  <info:fcres/a/b/c> a ns:Book ;
    fcrepo:hasParent <info:fcres/a> ;
    dc:title "Moby Dick" ;
    dc:creator "Herman Melville" ;
    dc:subject "Fishing" ;
    .
  <info:fcres/a/b/c#chapter1> a ns:BookChapter ;
    dc:title "Loomings." ;
    .
  <info:fcres/a/b/c#chapter2> a ns:BookChapter ;
    dc:title "The Carpet-Bag." ;
    .
}

# Previous states (versions) of a resource.
<info:fcstate/a/b/c:v1> {
  <info:fcres/a/b/c> a ns:Book ;
    fcrepo:hasParent <info:fcres/a> ;
    dc:title "Moby Dick" ;
    .
}

<info:fcstate/a/b/c:v2> {
  <info:fcres/a/b/c> a ns:Book ;
    fcrepo:hasParent <info:fcres/a> ;
    dc:title "Moby Dick" ;
    dc:creator "Herman Melvil" ;
    .
}

<info:fcstate/a/b/c:v3> {
  <info:fcres/a/b/c> a ns:Book ;
    fcrepo:hasParent <info:fcres/a> ;
    dc:title "Moby Dick" ;
    dc:creator "Herman Melville" ;
    .
}
